/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.supinfo.youfood.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author Michael
 */
@Entity
@Table(name="table_resto")
public class TableResto implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id_table")
    private Long id_table;
    
    @NotEmpty
    private String nom;
    
    @NotNull
    private int nombre_personnes;
    
    @OneToMany(mappedBy = "tableResto")
    private List<Commande> commandes;
    
    @ManyToOne
    @JoinColumn(name="fk_restaurant")
    private Restaurant resto;
    
    @ManyToOne
    @JoinColumn(name="fk_id_serveur")
    private Employe serveur;

    public TableResto() {
    }

    public TableResto(int nombre_personnes, String nom) {
        this.nombre_personnes = nombre_personnes;
        this.nom = nom;
    }

    public int getNombre_personnes() {
        return nombre_personnes;
    }

    public void setNombre_personnes(int nombre_personnes) {
        this.nombre_personnes = nombre_personnes;
    }

    public List<Commande> getCommandes() {
        return commandes;
    }

    public void setCommandes(List<Commande> commandes) {
        this.commandes = commandes;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public Long getId_table() {
        return id_table;
    }

    public void setId_table(Long id_table) {
        this.id_table = id_table;
    }

    public Restaurant getResto() {
        return resto;
    }

    public void setResto(Restaurant resto) {
        this.resto = resto;
    }

    public Employe getServeur() {
        return serveur;
    }

    public void setServeur(Employe serveur) {
        this.serveur = serveur;
    }
    
    public void addCommande(Commande commande)
    {
        if(commandes == null)
        {
            commandes = new ArrayList();
        }
        if(!commandes.contains(commande))
        {
            this.commandes.add(commande);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TableResto other = (TableResto) obj;
        if (this.id_table != other.id_table && (this.id_table == null || !this.id_table.equals(other.id_table))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + (this.id_table != null ? this.id_table.hashCode() : 0);
        return hash;
    }
    
    
}
